import * as types from 'store/mutations_types.js'

export default {
  [types.TOKEN]: (state, payload) => {
    try {
      uni.setStorageSync('token', payload);
      state.token = payload
    } catch (e) {
      uni.showModal({
        title: "异常",
        content: "存储token异常,可联系管理员！",
        showCancel: false,
        confirmText: "确定"
      })
    }
  },
  [types.LOGIN]: (state, payload) => {
    state.user = payload
  },
  [types.LOGOUT]: (state, payload) => {
    uni.removeStorage({
      key: 'token',
      success: function (res) {
        state.token = null
        state.user = null
      }
    })
  },
  [types.UPDATE_REFRESH]: (state, payload) => {
    state.is_refresh = payload.is_refresh
  }
}